package com.kkb.mybatis.test.mybatis;

import com.kkb.mybatis.framework.factory.SqlSessionFactory;
import com.kkb.mybatis.framework.sqlsession.SqlSession;
import com.kkb.mybatis.io.Resources;
import com.kkb.mybatis.framework.builder.SqlSessionFactoryBuilder;
import com.kkb.mybatis.po.User;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MybatisV3 {

    private SqlSessionFactory sqlSessionFactory;

    @Before
    public void before(){
        //全局配置文件
        String location = "mybatis-config-old.xml";
        InputStream inputStream = Resources.getResourceAsStream(location);
        //创建SqlSessionFactory
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }

    @Test
    public void test(){

        Map<String, Object> param = new HashMap();
        param.put("username", "王五");
        param.put("sex", "1");

        SqlSession sqlSession = sqlSessionFactory.openSession();

        List<User> users = sqlSession.selectList("test.queryUserByParams", param);

        System.out.println(users);

    }
}
